package com.atguigu.gmall.order.listener;

import com.atguigu.gmall.model.enums.OrderStatus;
import com.atguigu.gmall.order.config.DeadLetterMQConfig;
import com.atguigu.gmall.order.service.OrderInfoService;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Author: lx
 * @Time: 10:15
 * @Description:
 *
 * 订单接收消息的监听实现类
 */
//@Component
public class OrderConsumer {

    @Autowired
    private OrderInfoService orderInfoService;
    //取消订单
    @RabbitListener(queues = DeadLetterMQConfig.QUEUE_ORDER_CANCEL2)
    public void receiverOrderCancelMessage(Long orderId, Channel channel, Message message) throws Exception{

        System.out.println("orderId:" + orderId);
        System.out.println("接收时间：" + new Date());
        //取消订单
        orderInfoService.cancelOrder(orderId);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    }
}
